package com.thoughtworks.shoutbox.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.thoughtworks.shoutbox.client.room.RoomEntranceListener;
import com.thoughtworks.shoutbox.client.room.RoomView;
import com.thoughtworks.shoutbox.client.shouts.ShoutsView;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ShoutBox implements EntryPoint, RoomEntranceListener {
	private RoomView roomView;
	private ShoutsView shoutsView;
	private DeckPanel deckPanel;

	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		roomView = new RoomView();
		shoutsView = new ShoutsView();

		roomView.setRoomListener(this);
		shoutsView.setRoomListener(this);

		deckPanel = new DeckPanel();
		deckPanel.add(roomView);
		deckPanel.add(shoutsView);
		showRoomListingView();
		rootPanel.add(deckPanel);
	}

	@Override
	public void enterRoom(String roomId, String roomName) {
		shoutsView.showShoutsOf(roomId, roomName);
		showShoutsView();
	}

	@Override
	public void exitRoom(String roomName) {
		showRoomListingView();
	}

	private void showRoomListingView() {
		deckPanel.showWidget(0);
	}

	private void showShoutsView() {
		deckPanel.showWidget(1);
	}
}
